home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / prolog / brklyprl.lha / Emulator / inst_table.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-04-14  |  1.5 KB  |  64 lines

  1.  
  2. /* Copyright (C) 1988, 1989 Herve' Touati, Aquarius Project, UC Berkeley */
  3.  
  4. /* Copyright Herve' Touati, Aquarius Project, UC Berkeley */
  5.  
  6. #include <stream.h>
  7. #include <ctype.h>
  8. #include "hash_table.h"
  9. #include "string_table.h"
  10. #include "scan.h"
  11. #include "tags.h"
  12. #include "instr.h"
  13. #include "inst_args.h"
  14. #include "memory.h"
  15. #include "basics.h"
  16. #include "inst_table.h"
  17.  
  18. InstrType instr_types[] = {
  19. #define NAMES
  20. #define use(String,ID,Function,Arg1,Arg2,Arg3)\
  21.   {String, ID, {Arg1,Arg2,Arg3}, &Function},
  22. #include "instructions.h"
  23. #undef use
  24. #undef NAMES
  25.   };
  26.     
  27. HashTable instr_ID;
  28.  
  29. void InstrType::fill(Instr& instr, char** p)
  30. {
  31.   instr.ID = ID;
  32.   instr.exec = exec;
  33.   instr.arg1 = instr_args[ArgType[0]]->fill(p[0]);
  34.   instr.arg2 = instr_args[ArgType[1]]->fill(p[1]);
  35.   instr.arg3 = instr_args[ArgType[2]]->fill(p[2]);
  36. }
  37.   
  38. void InstrType::print(Instr& instr)
  39. {
  40.   cout << name << " ";
  41.   instr_args[ArgType[0]]->print(instr.arg1); cout << " ";
  42.   instr_args[ArgType[1]]->print(instr.arg2); cout << " ";
  43.   instr_args[ArgType[2]]->print(instr.arg3); cout << "\n";
  44. }
  45.  
  46. void init_instr_types(Scan& SC)
  47. {
  48.   for (int i = 0; i < LAST_INSTRUCTION; i++) 
  49.     instr_ID.bind(SC.intern(instr_types[i].name), instr_types[i].ID);
  50. }
  51.  
  52.  /*  what_to_update == ARG_LABEL or ARG_PROC */
  53. void InstrType::update(Instr& instr, int what_to_update)
  54. {
  55.   Cell *arg[3];
  56.   arg[0] = &(instr.arg1);
  57.   arg[1] = &(instr.arg2);
  58.   arg[2] = &(instr.arg3);
  59.   for (int i = 0; i < 3; i++) {
  60.     if (ArgType[i] == what_to_update)
  61.       *arg[i] = instr_args[ArgType[i]]->update(*arg[i]);
  62.   }
  63. }
  64.